#encoding=utf8

from pdf2image import convert_from_path
import os
from pdf2image.exceptions import (PDFInfoNotInstalledError,PDFPageCountError,PDFSyntaxError)


# soure file path
s_path='F:\\mycode\\sr_file\\20220526072240300.pdf'

# target image format


#  storage path
    # if not os.path.exist(outputFile):
    # os.mkdir(outputFile)

#单个文件的转变
# imgs=convert_from_path(s_path,thread_count=2)
# for i ,image in enumerate(imgs):
#     fname='image'+str(i)+'.jpg'
#     image.save(fname,"jpeg")


#批量文件转变
# Gain all pdf files
pdf_files=[filename for filename in os.listdir('F:\\mycode\\sr_file') if filename.endswith('.pdf')]

# 
for pdf_file in pdf_files:
    imgages=convert_from_path(pdf_file)
    print(pdf_file)
    for i,img in enumerate(images):
        fname=pdf_file+'_img'+str(i)+'.jpg'
        img.save(fname,'JPEG')
